package com.itheima04;

import java.util.Iterator;
import java.util.LinkedList;

/**
 * @author Xiao
 * @date 2021/7/17
 */
public class PrintLinkedList {
    /**
     * ArrayList
     *    创建一个存储学生对象的集合，存储3个学生对象，使用程序实现在控制台遍历该集合。
     */
    public static void main(String[] args) {
        LinkedList<Student> linkedList = new LinkedList<>();
        Student stu1 = new Student("阿良", 24);
        Student stu2 = new Student("左右", 25);
        Student stu3 = new Student("平安", 21);
        linkedList.add(stu1);
        linkedList.add(stu2);
        linkedList.add(stu3);
        for (Student stu : linkedList) {
            System.out.println(stu);
        }
        System.out.println("-----------");
        for (int i = 0; i < linkedList.size(); i++) {
            System.out.println(linkedList.get(i));
        }
        System.out.println("-----------");
        Iterator<Student> it = linkedList.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
    }
}
